package com.itsu.vtalk.controller;

import com.itsu.vtalk.entity.User;
import com.itsu.vtalk.exception.SystemBaseException;
import com.itsu.vtalk.service.LoginLogoutService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author suben
 * @createtime 2020/6/21 9:55
 **/
@Controller
public class VTalkController {

    @Resource
    private LoginLogoutService loginLogoutService;

    @GetMapping("/login")
    public String login(boolean kickout, HttpServletRequest request) {
        if (!kickout)
            kickout = (boolean) request.getAttribute("kickout");
        return "login";
    }

    @PostMapping("/login.do")
    public String sub2Login(User user, HttpServletRequest request) throws SystemBaseException {
        User data = loginLogoutService.checkLogin(user);
        request.getSession().setAttribute("loginUser", data);
        return "redirect:/index.html";
    }
}
